package com.jz.community.moduleshopping.integralGoods.adapter;

import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jz.community.basecomm.utils.BaseImageLoaderUtils;
import com.jz.community.basecomm.utils.Preconditions;
import com.jz.community.basecomm.utils.SHelper;
import com.jz.community.moduleshopping.R;
import com.jz.community.moduleshopping.integralGoods.bean.IntegralHistoryInfo;

import java.util.List;

/**
 * Created by Tony.Fan on 2018/7/2 09:37
 */
public class IntegralGoodsHistoryAdapter extends BaseQuickAdapter<IntegralHistoryInfo.EmbeddedBean.IntegraViewsBean, BaseViewHolder> {

    public IntegralGoodsHistoryAdapter(@Nullable List<IntegralHistoryInfo.EmbeddedBean.IntegraViewsBean> data) {
        super(R.layout.module_shopping_integral_goods_history_item_layout, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, IntegralHistoryInfo.EmbeddedBean.IntegraViewsBean item) {
        showIntegralGoodsInfo(helper, item);
    }

    private void showIntegralGoodsInfo(BaseViewHolder helper, IntegralHistoryInfo.EmbeddedBean.IntegraViewsBean item) {

        if (!Preconditions.isNullOrEmpty(item.getIcon())) {
            BaseImageLoaderUtils.getInstance().loadDefaltImage(mContext, helper.getView(R.id.integral_iv), item.getIcon());
        } else {
            helper.setImageResource(R.id.integral_iv, R.mipmap.integral_icon);
        }
        if (!Preconditions.isNullOrEmpty(item.getTitle())) {
            helper.setText(R.id.integral_name, item.getTitle());
        } else {
            helper.setText(R.id.integral_name, item.getCouponName());
        }

        if (!Preconditions.isNullOrEmpty(item.getUseStartDate())) {
            SHelper.vis(helper.getView(R.id.integral_start_time_tv));
            helper.setText(R.id.integral_start_time_tv, item.getUseStartDate() + "至" + item.getUseEndDate());
        } else {
            SHelper.gone(helper.getView(R.id.integral_start_time_tv));
        }
        helper.setText(R.id.integral_end_time_tv, item.getUseStartDate());
        helper.setText(R.id.integral_tv, item.getIntegral() + "");
    }
}
